package xin.vsftpd;

import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import xin.vsftpd.Config.Env;
import xin.vsftpd.job.VsftpdJob;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import static org.quartz.impl.StdSchedulerFactory.getDefaultScheduler;

/**
 * <pre>
 * 启动程序
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @version 1.0
 * @since 2019/7/9
 */
@Slf4j
public class BootStrap {
	
	public static void main(String[] args) {
		log.info("工具启动初始化任务");
		JobDetail job = newJob(VsftpdJob.class)
				.withIdentity("vsfptd_job", "vsfptd")
				.build();
		
		Trigger trigger = newTrigger()
				.withIdentity("vsfptd_trigger", "vsfptd")
				.withSchedule(cronSchedule((String) Env.get("corn")))
				.startNow()
				.build();
		try {
			Scheduler scheduler = getDefaultScheduler();
			scheduler.scheduleJob(job, trigger);
			scheduler.start();
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}
	
	
}
